package com.example.daojia.frametest.Activity;

import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import com.alibaba.android.arouter.launcher.ARouter;
import com.example.daojia.frametest.BusEvent.MessageStick;
import com.example.daojia.frametest.Service.MyService;
import com.example.daojia.frametest.R;

import org.greenrobot.eventbus.EventBus;

import butterknife.BindString;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class main_menu extends AppCompatActivity {
    @BindView(R.id.eventBus)
    Button eventBus;
    @BindView(R.id.aRouter)
    Button aRouter;
    @BindView(R.id.imageLoader)
    Button imageLoader;
    @BindView(R.id.retrofit)
    Button retrofit;
    @BindView(R.id.weex)
    Button weex;
    @BindView(R.id.rxBinding)
    Button rxBinding;
    @BindString(R.string.text)
    String textContent;
    String muri = "https://gss3.bdstatic.com/7Po3dSag_xI4khGkpoWK1HF6hhy/baike/c0%3Dbaike92%2C5%2C5%2C92%2C30/sign=670b6d918e18367ab984778f4f1ae0b1/0df431adcbef76099c6c392726dda3cc7cd99e27.jpg";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main_menu);
        //绑定初始化ButterKnife
        ButterKnife.bind(this);
        initview();
        Intent intent = new Intent(this, MyService.class);
        startService(intent);
    }

    private void initview() {
        eventBus.setText("EventBus");
        aRouter.setText("ARouter");
        imageLoader.setText("ImageLoader");
        retrofit.setText("Retrofit");
        weex.setText("Weex");
        rxBinding.setText("RxBinding");
    }

    @OnClick(R.id.eventBus)
    public void eventBusClick() {
        //发送粘性事件
        EventBus.getDefault().postSticky(new MessageStick("EventBus粘性事件"));
        ARouter.getInstance().build("/test/eventBus").navigation();
//        Toast.makeText(main_menu.this, "ARouter跳转", Toast.LENGTH_SHORT).show();
    }

    @OnClick({R.id.aRouter, R.id.imageLoader, R.id.retrofit, R.id.weex, R.id.rxBinding})
    public void viewClick(View v) {
        switch (v.getId()) {
            case R.id.aRouter:
                ARouter.getInstance().build("/test/aRouter")
                        .withString("data", "ARouter携带参数跳转")
                        .navigation();
//                Toast.makeText(main_menu.this, "EventBus多绑定事件！", Toast.LENGTH_SHORT).show();
                break;
            case R.id.imageLoader:
                Uri uri = Uri.parse("/test/imageLoader");
                ARouter.getInstance().build(uri)
                        .withString("data", muri)
                        .navigation();
//                Toast.makeText(main_menu.this, "ImageLoader多绑定事件！", Toast.LENGTH_SHORT).show();
                break;
            case R.id.retrofit:
                ARouter.getInstance().build("/test/retrofit").navigation();
//                Toast.makeText(main_menu.this, "Retrofit多绑定事件！", Toast.LENGTH_SHORT).show();
                break;
            case R.id.weex:
                ARouter.getInstance().build("/app/mweex").navigation();
//                Toast.makeText(main_menu.this, textContent, Toast.LENGTH_SHORT).show();
                break;
            case R.id.rxBinding:
                ARouter.getInstance().build("/app/rxBinding").navigation();
                break;
            default:
                break;
        }
    }

    @OnClick(R.id.rxjava)
    public void rxjavaTest() {
        ARouter.getInstance().build("/app/rxjava").navigation();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}
